www.gusucode.com > VC 2D游戏编辑器-源码程序 > VC 2D游戏编辑器-源码程序/code/mapedit_source/MapEditView1.cpp
//Download by http://www.NewXing.com // MapEditView.cpp : implementation of the CMapEditView class // #include "stdafx.h" #include "MapEdit.h" #include "MapEditDoc.h" #include "MapEditView.h" #include "Map.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif CToolDlg tooldlg; bool bIsDirty; extern char SelPic[MAX_PATH]; extern char SelFloor[MAX_PATH]; ///////////////////////////////////////////////////////////////////////////// // CMapEditView IMPLEMENT_DYNCREATE(CMapEditView, CView) BEGIN_MESSAGE_MAP(CMapEditView, CView) //{{AFX_MSG_MAP(CMapEditView) ON_COMMAND(ID_VIEW_TOOL, OnViewTool) ON_COMMAND(ID_FILE_NEW, OnFileNew) ON_WM_SHOWWINDOW() ON_COMMAND(ID_SELECT_BLOCK, OnSelectBlock) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMapEditView construction/destruction CMapEditView::CMapEditView() { // TODO: add construction code here tooldlg.m_hWnd=0; bIsDirty=false; } CMapEditView::~CMapEditView() { } ///////////////////////////////////////////////////////////////////////////// // CMapEditView drawing void CMapEditView::OnDraw(CDC* pDC) { CMapEditDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here } ///////////////////////////////////////////////////////////////////////////// // CMapEditView printing BOOL CMapEditView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CMapEditView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CMapEditView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CMapEditView diagnostics #ifdef _DEBUG void CMapEditView::AssertValid() const { CView::AssertValid(); } void CMapEditView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CMapEditDoc* CMapEditView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMapEditDoc))); return (CMapEditDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMapEditView message handlers void CMapEditView::OnViewTool() { // TODO: Add your command handler code here if (tooldlg.m_hWnd) tooldlg.ShowWindow(SW_SHOW); } void CMapEditView::OnInitialUpdate() { CView::OnInitialUpdate(); // TODO: Add your specialized code here and/or call the base class RECT wrect; int xSize = ::GetSystemMetrics(SM_CXSCREEN); int ySize = ::GetSystemMetrics(SM_CYSCREEN); tooldlg.Create(IDD_TOOL,NULL); tooldlg.GetWindowRect(&wrect); tooldlg.SetWindowPos(0,xSize-wrect.right-20,ySize/8,0,0, SWP_NOSIZE); } void CMapEditView::OnFileNew() { // TODO: Add your command handler code here if (bIsDirty) // 改动过了 { CString msg; msg="地图内容已经改变。想保存么?"; int result; result=MessageBox(msg,"Warning",MB_YESNOCANCEL | MB_ICONWARNING); if (result==IDYES) // save { // OnFileSave(); if (bIsDirty==false) // 保存过了。如果还是true,说明没有保存。取消了 { szFileName="Unknown.map"; bIsDirty=true; SetWinTitle(); NewMapFile(); } } else if (result==IDNO) // 不用保存了 NewMapFile(); } else NewMapFile(); } void CMapEditView::NewMapFile() { // TODO: Add your command handler code here CNewMap newmap; newmap.m_nHeight=20; newmap.m_nWidth=20; DWORD result=newmap.DoModal(); if (result==IDOK) { if(newmap.m_issquare) newmap.m_nHeight = newmap.m_nWidth; szFileName="Unknown.map"; } } /* void CMapEditView::OnFileOpen() { // TODO: Add your command handler code here if (bIsDirty) // 改了 { CString msg; msg="地图内容已经改变。想保存么?"; int result; result=MessageBox(msg,"Warning",MB_YESNOCANCEL | MB_ICONWARNING); if (result==IDYES) // save OnFileSave(); else if (result==IDCANCEL) return; } // 打开文件对话框 // OpenMapFile(); } void CMapEditView::OpenMapFile() { } void CMapEditView::OnFileSave() { // TODO: Add your command handler code here if (bIsDirty) // 改变了 { // if (szFileName == "Unknown.map") // { // OnFileSaveAs(); // return; // } bIsDirty=false; // SaveMapFile(); } } void CMapEditView::OnFileSaveAs() { // TODO: Add your command handler code here // SaveMapFile(); } */ void CMapEditView::OnShowWindow(BOOL bShow, UINT nStatus) { CView::OnShowWindow(bShow, nStatus); // TODO: Add your message handler code here szFileName="Unknown.map"; } void CMapEditView::SetWinTitle() { CString WinTitle,FileName; int pos=szFileName.ReverseFind('\\'); if (pos == -1) FileName = szFileName; else FileName = szFileName.Right(szFileName.GetLength() - pos -1); CString csWinTitle; if (bIsDirty) csWinTitle="MapEdit - " + FileName + "*"; else csWinTitle="MapEdit - " + FileName; AfxGetMainWnd()->SetWindowText(csWinTitle); } void CMapEditView::OnSelectBlock() { // TODO: Add your command handler code here if (bIsSeleBlock==true) bIsSeleBlock=false; else bIsSeleBlock=true; }